import { useLocalStorage } from "@vueuse/core";
import { defineStore } from "pinia";
import LocalSetting from "../entity/LocalSetting";
import SettingLayoutEnum from "../enumeration/SettingLayoutEnum";
import SettingOrderEnum from "../enumeration/SettingOrderEnum";

export const useLocalSettingStore = defineStore('local-setting', {
    state: () => ({
        instance: useLocalStorage('local-setting', {
            downloadPath: utools.getPath('downloads'),
            layout: SettingLayoutEnum.INFO,
            order: SettingOrderEnum.DEFAULT
        } as LocalSetting)
    }),
    getters: {
        downloadPath: (state): string => state.instance.downloadPath || utools.getPath('downloads'),
        layout: (state): SettingLayoutEnum => state.instance.layout || SettingLayoutEnum.INFO,
        order: (state): SettingOrderEnum => state.instance.order || SettingOrderEnum.DEFAULT
    },
    actions: {
        save(record: LocalSetting) {
            this.instance = record;
        },
        setLayout(layout: SettingLayoutEnum) {
            this.instance.layout = layout;
        },
        setOrder(order: SettingOrderEnum) {
            this.instance.order = order;
        }
    }
})